#ifndef DATACONNECTION_H
#define	DATACONNECTION_H

#include "ServerSocket.h"
#include "ClientSocket.h"
#include "DataConnectionObserver.h"
#include "ByteStream.h"

class DataConnection
{
public:
	enum TransferDirection
	{
		NONE,
		UPLOAD,
		DOWNLOAD
	};
	typedef enum TransferDirection TransferDirection;


	DataConnection();
	~DataConnection();

	void SetTransferDirection(DataConnection::TransferDirection direction);
	void RegisterObserver(DataConnectionObserver* newObserver);
	void RemoveObserver();
	void SetActive(DataConnection::TransferDirection direction, const std::string& server, unsigned short port);
	void Upload(const void* data, unsigned int size);
	bool IsDead() const;
	Socket& Socket() const;
	void SetFileSink(const std::string& path);
	void SetFileSource(const std::string& path);

	bool IsDownloadConnection() const;
	bool IsUploadConnection() const;
	bool IsUploadQueueEmpty() const;

	void UploadUpdate();
	void DownloadUpdate();

protected:

private:
	ByteStream dataupload, datadownload;
	FILE *filesource;
	FILE *filesink;
	ServerSocket *server; // for future passive mode support
	ClientSocket *client;
	DataConnectionObserver *observer;
	TransferDirection transferDirection;

	DataConnection(const DataConnection& rhs); // no copy-constructor
	
	void Clear();
};

#endif //DATACONNECTION_H
